var md5Util= require("md5.js");
//服务地址
const  requestUrl= "http://127.0.0.1:8080"
const  appVersion ="1.0"
function jsonSort(jsonObj) {
  let arr=[];
  for(var key in jsonObj){
    arr.push(key)
  }
  arr.sort();
  let str='';
  for(var i in arr){
    str +=arr[i]+"="+jsonObj[arr[i]]+"&"
  }
  return str.substr(0,str.length-1)
}

function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()
  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function getSignValue(param){
  var md5Str = "";
  if (param == null){
    md5Str = md5Util.md5(appVersion);
   // console.log("===str===",appVersion)
  }else{
   // console.log("===str===",jsonSort(param))
    md5Str =  md5Util.md5(jsonSort(param));
  }
  //console.log("===md5===",md5Str)
  return md5Str
}
//业务变量
const sysConst= {
  //图标
  cartIcon: '../../images/cart-null.png',
  removeIcon: '../../images/remove.png',
  addIcon: '../../images/add.png',
  soleOVerIcon:'../../images/saleOve.png',
  successIcon: '../../images/success.png',
  //获取用户信息  获取openid 和 unionid （不一定有）
  getUserInfoPath:requestUrl+"/wxApp/user/getUserInfo",

  //头部滚动条
  sliderListPath:requestUrl+"/wxApp/mall/product/slider",
  //店长推荐
  recommendPath:requestUrl+"/wxApp/mall/product/recommend",
  //产品详情
  productDetailPath:requestUrl+"/wxApp/mall/product/productDetail",
  //产品分类
  classifyPtah:requestUrl+"/wxApp/mall/product/classify",

  //加入购物车
  addCartPath:requestUrl+"/wxApp/mall/cart/addCart",
  //删除购物车产品
  removeCartPath:requestUrl+"/wxApp/mall/cart/removeCart",
  //查询购物车
  getCartPath:requestUrl+"/wxApp/mall/cart/getCart",

  //获取地址
  getAddressPath:requestUrl+"/wxApp/mall/address/getAddress",
  //删除地址
  removeAddressPath:requestUrl+"/wxApp/mall/address/removeAddress",
  //添加地址
  addAddressPath:requestUrl+"/wxApp/mall/address/addAddress",
  //获取地址
  getAddressByIdPath:requestUrl+"/wxApp/mall/address/getAddressById",
  //修改地址
  editAddressPath:requestUrl+"/wxApp/mall/address/editAddress",

  //下单
  orderPath:requestUrl+"/wxApp/mall/order/order",
  //订单列表
  userOrderPath:requestUrl+"/wxApp/mall/order/userOrder",
  //订单详情
  orderDetailPath:requestUrl+"/wxApp/mall/order/orderDetail",
  //确认收货
  takeDeliveryPath:requestUrl+"/wxApp/mall/order/takeDelivery",
  //取消订单
  cancelOrderPath:requestUrl+"/wxApp/mall/order/cancelOrder",
}
module.exports = {
  sysConst: sysConst,
  appVersion: appVersion,
  formatTime: formatTime,
  getSignValue: getSignValue
}